$(function(){
  $('.btn-login').on('click',function(){
    let ins = $('input');
  let patt = /^\w+[@]{1}(\w+[\.]+[a-z0-9A-Z]+)+$/;
  if (!patt.test(ins[0].value)) {
  $('#modelId').modal();
  $('.container-fluid').text('邮箱有误');
  return false;
  };
   let  patt2 = /^\w{4,20}$/;
   if (!patt2.test(ins[1].value)) {
  $('#modelId').modal();
  $('.container-fluid').text('密码有误');
    return false;
  };
  // 收集数据
  let data = $('.login-wrap').serialize();
  // console.log(data);
  $.post('/admin_do_login',data,(res)=>{
    console.log(res);
    let tip = null;
    if(res.code == 200){
      tip = '登陆成功';
      isSuccess = true;
    }else{
      tip = '登陆失败';
    };
    $('.container-fluid').text(tip);
    $('#modelId').modal();
  });
  });
  let isSuccess = false;
  $('#modelId').on('hide.bs.modal',()=>{
  // 判断是否成功
    if(isSuccess){
      location.href = 'http://127.0.0.1:8989/admin/index';
    }
  });
});